package com.uzhie.jt808.msg.entity.JT_200;

import com.uzhie.jt808.msg.entity.BitConverter;
import com.uzhie.jt808.msg.entity.IPositionAdditionalItem;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * 1078 报警扩展,存储器异常告警
 * Created by lilongfei on 2018/7/31.
 */
public class Media_Storager implements IPositionAdditionalItem {

    //设备存储器状态
    int channel;

    //正常设备状态
    Map<Integer,Integer> status;
    //灾备设备状态
    Map<Integer,Integer> status2;

    public Map<Integer, Integer> getStatus() {
        return status;
    }

    public void setStatus(Map<Integer, Integer> status) {
        this.status = status;
    }

    public Map<Integer, Integer> getStatus2() {
        return status2;
    }

    public void setStatus2(Map<Integer, Integer> status2) {
        this.status2 = status2;
    }

    public int getChannel() {
        return channel;
    }

    public void setChannel(int channel) {
        this.channel = channel;
    }

    @Override
    public int getAdditionalId() {
        return 0x017;
    }

    @Override
    public byte getAdditionalLength() {
        return 0x02;
    }

    @Override
    public byte[] WriteToBytes() {
        return BitConverter.GetBytes(channel);
    }

    @Override
    public void ReadFromBytes(byte[] bytes) {
        status = new HashMap<>();
        status2 = new HashMap<>();
        for (int i=0  ;i<12;i ++){
            byte t = (byte) ((BitConverter.ToUInt16(bytes,0) >> (i)) & 0x0001);
            if (t == 1) status.put(i, (int) t);
//            System.out.println("当前存储位:" + i + ", 设备状态 : " + (t==0 ? "正常":"丢失"));
        }

        for (int i=12  ;i<16;i ++){
            byte t = (byte) ((BitConverter.ToUInt16(bytes,0) >> (i)) & 0x0001);
            if (t == 1) status2.put(i, (int) t);
//            System.out.println("当前存储位:" + i + ", 设备状态 : " + (t==0 ? "正常":"丢失"));
        }
        setChannel(BitConverter.ToUInt16(bytes,0));
    }

    public static void main (String[] arge){
        Media_Storager order = new Media_Storager();
        order.ReadFromBytes(BitConverter.GetBytes(3));
    }
}
